package com.cy.service.system.impl;

import java.io.Serializable;
import java.util.LinkedHashMap;

import javax.servlet.ServletContext;

import org.springframework.stereotype.Service;
import org.springframework.web.context.ContextLoader;

import com.cy.bean.QueryResult;
import com.cy.bean.system.Blogroll;
import com.cy.service.base.DAOSupport;
import com.cy.service.system.BlogrollService;

/**
 * 友情链接Service接口实现类
 * @author CY
 *
 */
@Service
public class BlogrollServiceBean extends DAOSupport<Blogroll> implements BlogrollService {

	public void save(Blogroll entity) {
		super.save(entity);
		updateApplication();
	}

	public void update(Blogroll entity) {
		super.update(entity);
		updateApplication();
	}

	public void delete(Serializable... entityID) {
		super.delete(entityID);
		updateApplication();
	}

	public void updateApplication() {
		ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
		String where = "o.blogrool_visible = true";
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		orderby.put("blogrool_order", "asc");
		QueryResult<Blogroll> blogrolls = this.getScrollData(-1,-1,where,null,orderby);
		servletContext.setAttribute("blogrolls", blogrolls);
		System.out.println("************");
	}
}
